//package com.plian.system.service.yth.impl;
//
//import com.baomidou.dynamic.datasource.annotation.DS;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.plian.Tools.CollectionUtil;
//import com.plian.system.entity.tb.TripleSystem;
//import com.plian.system.entity.yth.Regulation;
//import com.plian.system.mapper.yth.RegulationMapper;
//import com.plian.system.service.yth.IRegulationService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.time.ZoneId;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//import java.util.Optional;
//
//@Slf4j
//@Service
//public class RegulationServiceImpl extends ServiceImpl<RegulationMapper, Regulation> implements IRegulationService {
//
//    private final String YTH_DATASOURCE_TYPE = "3";
//
//    @Transactional(rollbackFor = Exception.class)
//    @DS("slave_1")
//    @Override
//    public List<TripleSystem> getAllProject(Date startTime, Date endTime) {
//        List<TripleSystem> tripleSystems = new ArrayList<>();
//
//        List<Regulation> allRegulation = list(new LambdaQueryWrapper<Regulation>()
//                .gt(Optional.ofNullable(startTime).isPresent(),Regulation::getCreateTime,startTime)
//                .le(Optional.ofNullable(endTime).isPresent(),Regulation::getCreateTime,endTime)
//        );
//        if (CollectionUtil.isNotEmpty(allRegulation)){
//            tripleSystems = conversion(allRegulation);
//        }
//        return tripleSystems;
//    }
//    private List<TripleSystem> conversion(List<Regulation> regulations){
//        List<TripleSystem> tripleSystems= new ArrayList<>();
//        ZoneId zone = ZoneId.systemDefault();
//        for (Regulation regulation:regulations){
//            TripleSystem tripleSystem = new TripleSystem();
//            tripleSystem.setSystemName(regulation.getName());
//            switch (regulation.getType()){
//                case 0:
//                    tripleSystem.setSystemType("142002");
//                    break;
//                case 1:
//                    tripleSystem.setSystemType("142001");
//                    break;
//                default:
//                    break;
//
//            }
//            tripleSystem.setSystemNumber(regulation.getNumber());
//            Optional.ofNullable(regulation.getReportUserId()).ifPresent(m ->{
//                tripleSystem.setReportUser(m.toString());
//            });
//            Optional.ofNullable(regulation.getReportTime()).ifPresent( m ->{
//                tripleSystem.setReportTime(Date.from(m.atStartOfDay().atZone(zone).toInstant()));
//            });
//            Optional.ofNullable(regulation.getReportOrgId()).ifPresent(m ->{
//                tripleSystem.setFillingUnitId(m.toString());
//            });
//            Optional.ofNullable(regulation.getPublishTime()).ifPresent( m ->{
//                tripleSystem.setSystemUpdateTime(Date.from(m.atStartOfDay().atZone(zone).toInstant()));
//            });
//            Optional.ofNullable(regulation.getStartTime()).ifPresent( m ->{
//                tripleSystem.setEffectTime(Date.from(m.atStartOfDay().atZone(zone).toInstant()));
//            });
//
//            Optional.ofNullable(regulation.getEndTime()).ifPresent( m ->{
//                tripleSystem.setFailureTime(Date.from(m.atStartOfDay().atZone(zone).toInstant()));
//            });
//            tripleSystem.setSystemText(regulation.getSummary());
//            tripleSystem.setDataSource(YTH_DATASOURCE_TYPE);
//            tripleSystem.setDataSourceId(regulation.getId().toString());
//            tripleSystem.setAttachIds(regulation.getAttachIds());
//            tripleSystems.add(tripleSystem);
//        }
//        return tripleSystems;
//    }
//}
